package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ErpContract;
import com.ruoyi.system.service.IErpContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ERP-合同Controller
 * 
 * @author ruoyi
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/system/contract")
public class ErpContractController extends BaseController
{
    @Autowired
    private IErpContractService erpContractService;

    /**
     * 查询ERP-合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpContract erpContract)
    {
        startPage();
        List<ErpContract> list = erpContractService.selectErpContractList(erpContract);
        return getDataTable(list);
    }

    /**
     * 导出ERP-合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contract:export')")
    @Log(title = "ERP-合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpContract erpContract)
    {
        List<ErpContract> list = erpContractService.selectErpContractList(erpContract);
        ExcelUtil<ErpContract> util = new ExcelUtil<ErpContract>(ErpContract.class);
        util.exportExcel(response, list, "ERP-合同数据");
    }

    /**
     * 获取ERP-合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(erpContractService.selectErpContractById(id));
    }

    /**
     * 新增ERP-合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:add')")
    @Log(title = "ERP-合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpContract erpContract)
    {
        return toAjax(erpContractService.insertErpContract(erpContract));
    }

    /**
     * 修改ERP-合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:edit')")
    @Log(title = "ERP-合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpContract erpContract)
    {
        return toAjax(erpContractService.updateErpContract(erpContract));
    }

    /**
     * 删除ERP-合同
     */
    @PreAuthorize("@ss.hasPermi('system:contract:remove')")
    @Log(title = "ERP-合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpContractService.deleteErpContractByIds(ids));
    }
}
